from enum import Enum
from logging import warning

from pages.serial_port_page import SerialPortPage
from pages.ble_center import BleCenterPage
from pages.sctp_client import SctpClientPage
from pages.sctp_server import SctpServerPage
from pages.tcp_client import TcpClientPage
from pages.tcp_server import TcpServerPage
from pages.udp_client import UdpClientPage
from pages.udp_server import UdpServerPage
from pages.web_socket_client import WebSocketClientPage
from pages.web_socket_server import WebSocketServerPage


class PageType(Enum):
    SERIAL_PORT = 1
    BLE_CENTER = 2
    SCTP_CLIENT = 3
    SCTP_SERVER = 4
    TCP_CLIENT = 5
    TCP_SERVER = 6
    UDP_CLIENT = 7
    UDP_SERVER = 8
    WEB_SOCKET_CLIENT = 9
    WEB_SOCKET_SERVER = 10


class PageFactory:
    @staticmethod
    def create_page(page_type, parent=None):
        if page_type == PageType.SERIAL_PORT:
            page = SerialPortPage(parent)
        elif page_type == PageType.BLE_CENTER:
            page = BleCenterPage(parent)
        elif page_type == PageType.SCTP_CLIENT:
            page = SctpClientPage(parent)
        elif page_type == PageType.SCTP_SERVER:
            page = SctpServerPage(parent)
        elif page_type == PageType.TCP_CLIENT:
            page = TcpClientPage(parent)
            page.is_client = True
            page.is_web_socket = False
        elif page_type == PageType.TCP_SERVER:
            page = TcpServerPage(parent)
            page.is_client = False
            page.is_web_socket = False
        elif page_type == PageType.UDP_CLIENT:
            page = UdpClientPage(parent)
            page.is_client = True
            page.is_web_socket = False
        elif page_type == PageType.UDP_SERVER:
            page = UdpServerPage(parent)
            page.is_client = False
            page.is_web_socket = False
        elif page_type == PageType.WEB_SOCKET_CLIENT:
            page = WebSocketClientPage(parent)
            page.is_client = True
            page.is_web_socket = True
        elif page_type == PageType.WEB_SOCKET_SERVER:
            page = WebSocketServerPage(parent)
            page.is_client = False
            page.is_web_socket = False
        else:
            warning("Invalid pages type: %s", page_type)
            return None

        page.pack(expand=1, fill="both")
        page.init_ui()
        return page
